<template>
	<view class="vip">
		<view class="box">
			<view class="infoli">
				<view class="left">
					成员邀请码
				</view>
				<view class="right">
					<input type="text" placeholder="请输入成员邀请码" v-model="code" disabled>
				</view>
			</view>
		</view>
		<view class="box">
			<view class="infoli">
				<view class="left">
					转账金额
				</view>
				<view class="right">
					<input type="number" placeholder="请输入金额" v-model="num">
				</view>
			</view>
		</view>
		<view class="box">
			<view class="infoli">
				<view class="left">
					支付密码
				</view>
				<view class="right">
					<input type="password" placeholder="请输入支付密码" v-model="password">
				</view>
			</view>
		</view>
		<view class="box">
			<view class="infoli">
				<view class="left">
					转账类型
				</view>
				<view class="right">
					<radio-group @change="change">
						<label>
							<radio value="4" :checked="type == 4" /><text>余额</text>
						</label>
						<label>
							<radio value="1" :checked="type == 1" /><text>积分</text>
						</label>
					</radio-group>
				</view>
			</view>
		</view>
		<view class="tips">
			<text>可用余额 : {{user.balance_4}}</text>
			<text>可用积分 : {{user.balance_1}}</text>
		</view>
		<view>
			<button class="btn" :loading="loading" :disabled="loading" @click="transfer">去支付</button>
		</view>
	</view>
</template>

<script>
	import {
		transfer,
		UserInfo
	} from "@/api/api.js"
	export default {
		data() {
			return {
				range: [],
				type: 4,
				username: '',
				num: '',
				password: '',
				loading: false,
				user: [],
				balance: '0.000',
				code: ''
			}
		},
		onLoad(e) {
			if (e.code) this.code = e.code
			// this.commonParam()
			this.UserInfo()
		},
		methods: {
			change(e) {
				this.type = e.detail.value
			},
			UserInfo() {
				UserInfo().then(res => {
					if (res.status == 1) {
						this.user = res.data
					}
				})
			},
			transfer() {
				var that = this

				if (that.num == '') {
					return uni.$showMsg('请输入金额')
				}
				if (that.password == '') {
					return uni.$showMsg('请输入支付密码')
				}
				that.loading = true
				transfer({
					num: that.num,
					recommend_code: that.code,
					password: that.password,
					balance_type: that.type
				}).then(res => {
					that.loading = false
					uni.$showMsg(res.message)
					if (res.status == 1) {
						that.num = ''
						that.username = ''
						that.password = ''
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		padding-top: 10px;
		background: #f2f2f2;
	}

	.uni-select {
		border: 1px solid #eee !important;
		height: 40px !important;
		border-bottom: unset;
	}

	.box {
		width: 96%;
		margin: 0 auto;
		margin-top: 10px;
		background: #fff;
		border-radius: 5px;
		padding: 10px 12px;
		box-sizing: border-box;
		box-shadow: 0 0 5px #d5d5d5;

		.title {
			font-weight: bold;
			font-size: 15px;
		}

		.infoli {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 2px 0;

			.left {
				width: 30%;
				font-weight: bold;
			}

			.right {
				width: 70%;
				display: flex;
				align-items: center;

				input {
					font-size: 14px;
					padding-bottom: 5px;
				}

				label {
					margin-bottom: 0;
				}
			}
		}

		.inputli {
			margin-top: 10px;

			input {
				font-size: 16px;
				padding: 10px 0;
				color: #FF3C29;
			}
		}
	}

	.tips {
		width: 92%;
		margin: 0 auto;
		color: #777;
		font-size: 12px;
		margin-top: 10px;

		text {
			margin-right: 15px;
		}
	}

	.btn {
		width: 90%;
		color: #fff;
		font-size: 15px;
	}
</style>